import { createRouter, createWebHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";
import AboutView from "../views/AboutView.vue";
import STestView from "../views/spider_tools/SpiderTest.vue";
import SIndexView from "../views/spider_tools/SpiderIndex.vue";
import Scookie from "../views/spider_tools/SFormatter.vue";
import TextComparison from "../views/spider_tools/TextComparison.vue";
import CryPto from "../views/crypto/CryPto.vue";
import MdInd from "../views/md/MDIndex.vue";
import MDedit from "../views/md/MDedit.vue";
import Login from "../views/login/loginIndex.vue";
import UserInfo from "../views/user/UserView.vue";
import curlView from "../views/curl/CurlView.vue";
import pdfView from "../views/pdf/pdfView.vue";
import loginCode from "../views/etax/loginCode.vue";
import HtmlRender from "../views/html/HtmlRender.vue";
import jsonFormat from "../views/spider_tools/FormatterJson.vue";
import RpcTaskView from "../views/rpc/RpcTaskView.vue";
import favicon from "@/assets/favicon.png";
const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
    meta: {
      title: "apitool首页",
      icon: "mdi mdi-alpha-p-box",
    },
  },
  {
    path: "/rpc",
    name: "rpc",
    component: RpcTaskView,
    meta: {
      title: "在线rpc",
      icon: "mdi mdi-home",
    },
  },
  {
    path: "/html/render",
    name: "render",
    component: HtmlRender,
    meta: {
      title: "html渲染",
    },
  },
  {
    path: "/curl",
    name: "curl",
    component: curlView,
    meta: {
      title: "curl转换",
    },
  },
  {
    path: "/user",
    name: "user",
    component: UserInfo,
    meta: {
      title: "用户中心",
    },
  },
  {
    path: "/crypto",
    name: "crypto",
    component: CryPto,
    meta: {
      title: "加解密工具",
    },
  },
  {
    path: "/login",
    name: "Login",
    component: Login,
    meta: {
      title: "登录",
    },
  },
  {
    path: "/md",
    name: "md",
    component: MdInd,
    meta: {
      title: "文档中心",
    },
  },
  {
    path: "/md/:itemName",
    name: "mdedit",
    meta: {
      title: "md编辑",
      breadcrumb: "md编辑",
    },
    component: MDedit,
  },
  {
    path: "/spider/test/:itemName",
    name: "spidertest",
    meta: {
      breadcrumb: "接口测试",
      title: "接口测试",
    },
    component: STestView,
  },
  {
    path: "/comparison",
    name: "文本比对",
    meta: {
      breadcrumb: "文本比对",
      title: "文本比对",
    },
    component: TextComparison,
  },

  {
    path: "/spider/index",
    name: "测试首页",
    component: SIndexView,
  },
  {
    path: "/formatting",
    name: "格式化",
    component: Scookie,
    meta: {
      title: "格式化",
    },
  },
  {
    path: "/formatting/json",
    name: "Json格式化",
    component: jsonFormat,
    meta: {
      title: "Json格式化",
    },
  },

  {
    path: "/about",
    name: "about",
    component: AboutView,
    meta: {
      title: "about",
    },
  },
  {
    path: "/pdf",
    name: "pdf",
    component: pdfView,
    meta: {
      title: "pdf",
    },
  },
  {
    path: "/etax/loginCode",
    name: "loginCode",
    component: loginCode,
    meta: {
      title: "loginCode",
    },
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

router.afterEach((to) => {
  document.title = to.meta.title;
  const iconLink =
    document.querySelector("link[rel~='icon']") ||
    document.createElement("link");
  iconLink.type = "image/x-icon";
  iconLink.rel = "icon";
  iconLink.href = to.meta.icon || favicon; // 默认使用UserImage
  document.head.appendChild(iconLink);
});

export default router;
